package com.xinli.xinlifm.view.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.xinli.xinlifm.utils.ConstantValue;

import java.util.Date;

/**
 * Created by zz on 16-10-14.
 */

public class MusicBroadcast extends BroadcastReceiver {
    private Handler handler;

    public MusicBroadcast(Handler handler) {
        this.handler = handler;
    }

    public MusicBroadcast() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        int status = intent.getIntExtra("status", -1);
        Message message = handler.obtainMessage();
        switch (status){
            case ConstantValue.START:
                    message.what=ConstantValue.START;
                break;
            case ConstantValue.STOP:
                    message.what = ConstantValue.STOP;
                break;
            case ConstantValue.seek_bar_completion:
                    message.what = ConstantValue.seek_bar_completion;
                break;
             case ConstantValue.RESTART:
                    message.what = ConstantValue.RESTART;
                break;


        }
        message.sendToTarget();




//        int status = intent.getIntExtra("status", -1);
//        int seek = intent.getIntExtra("seekBar", -1);
////        intent.putExtra("timeText","-"+simpleDateFormat.format(new Date(duration-mediaPlayer.getCurrentPosition()))+"");
////        intent.putExtra("seekBarProgress",seekbar.getProgress());
//        int seekBarProgress = intent.getIntExtra("seekBarProgress", -1);
//        String timeText = intent.getStringExtra("timeText");
//        switch (status) {
//            case ConstantValue.is_playing:
//
//                break;
//        }
//        if (seek != -1) {
//            Message message = handler.obtainMessage();
//            message.arg1 = seek;
//            switch (seek) {
//                case ConstantValue.seek_bar_completion:
//                    message.what = ConstantValue.seek_bar_completion;
//                    break;
//                case 10:
//                    message.what = 10;
//                    message.obj = timeText;
//                    Log.e("自定义标签", "类名==MusicBroadcast" + "方法名==onReceive=====:" + "");
//                    message.arg1 = seekBarProgress;
//
//                    break;
//
//                default:
//                    message.what = ConstantValue.seek_bar_length;
//                    break;
//
//            }
//            message.sendToTarget();
//        }
    }
}
